package com.xkstream.client.presenter;

import com.xkstream.client.api.LiveApi;
import com.xkstream.client.api.LiveService;
import com.xkstream.client.base.BaseData;
import com.xkstream.client.base.BasePresenterImpl;
import com.xkstream.client.rx.RxHelper;
import com.xkstream.client.rx.RxObserver;

import java.util.Map;

/**
 * Created by xiaoyi on 2017-10-31.
 */

public class LiveSettingPresenter extends BasePresenterImpl implements
        LiveSettingContract.Presenter {
    private LiveSettingContract.View view;
    private LiveService liveService;

    public LiveSettingPresenter(LiveSettingContract.View view) {
        this.view = view;
        this.liveService = LiveApi.getInstance().service;
    }

    @Override
    public void applySettings(Map<String, Object> params) {
        view.showLoading();
        liveService.applyLiveSttings(params)
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData>(this) {
                    @Override
                    protected void onSuccess(BaseData data) {
                        view.hideLoading();
                        view.showResult(data);
                    }

                    @Override
                    protected void onFail(String message) {
                        view.hideLoading();
                    }
                });
    }
}
